package com.bgIntlgn.client.entity.humanResources;

import yuhuibear.poat.annotations.action.AutoGenerateValue;
import yuhuibear.poat.annotations.relation.Field;
import yuhuibear.poat.annotations.relation.Table;
import yuhuibear.poat.object.bean.Bean;

/**
 * 建立数据库实体－－部门，为了序列化实现Bean
 * 
 * @author sk-32
 * 
 */
@Table(name = "departments", constrain = "")
public class Department implements Bean {

	public static final String Dash = ">";

	@AutoGenerateValue(skipOnNull = true, sqlToGet = "select currval('departments_id_seq')")
	@Field(name = "id", type = "bigserial", constrain = "primary key")
	private Long id;

	/**
	 * 父节点
	 */
	@Field(name = "parent_id", type = "int8", constrain = "references departments(id)on update cascade on delete cascade")
	private Long parentId;

	/**
	 *部门名称
	 */
	@Field(name = "name", type = "varchar(100)", constrain = "")
	private String name;

	/**
	 * 部门默认角色. not null references roles(name)
	 */
	@Field(name = "default_role", type = "char(40)", constrain = " references roles(name)")
	private String defaultRole;

	/**
	 * 部门描述
	 */
	@Field(name = "description", type = "varchar(500)", constrain = "")
	private String description;

	public String toString() {
		return "[id: " + id + ", name: " + name + ", parent_id: " + parentId + ", role: "
				+ defaultRole;
	}

	public boolean equals(Object o) {
		Department d = (Department) o;
		return name == d.getName() && d.getParentId() == parentId;
	}

	public int hashCode() {
		return id == null ? -1 : id.intValue();
	}

	public String getDefaultRole() {
		return defaultRole;
	}

	public String getDescription() {
		return description;
	}

	public String getName() {
		return name;
	}

	public Long getId() {
		return id;
	}

	public Long getParentId() {
		return parentId;
	}

	public void setDefaultRole(String defaultRole) {
		if (defaultRole != null) this.defaultRole = defaultRole.trim();
	}

	public void setName(String departmentName) {
		if (departmentName != null) name = departmentName.trim();
		else name = null;
	}

	public void setDescription(String description) {
		if (description != null) this.description = description.trim();
	}

	public void setId(Long id) {
		this.id = id;
	}

	public void setParentId(Long parentId) {
		this.parentId = parentId;
	}

}
